package com.cangxuan.backend.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * author:彭伟辰、杨刚
 * 版本更新接口
 */
@Api(tags = "版本相关接口")
@RestController
@RequestMapping("version")
@RefreshScope
public class VersionController extends BaseController{
    @Value("${verSion.number}")
    String versionNumber;
    @Value("${verSion.illustrate}")
    String illustrate;
    @Value("${verSion.isItMandatory}")
    Boolean isItMandatory;


    @GetMapping("ver")
    @ApiOperation("查询版本")
    public Object versionQuery(){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("versionNumber",versionNumber);
        jsonObject.put("illustrate",illustrate);
        jsonObject.put("isItMandatory",isItMandatory);
        return success(jsonObject);
    }

    @GetMapping("QR")
    @ApiOperation("生成二维码")
    public void produceQR() throws IOException {
        response.sendRedirect("/cangxuan."+versionNumber+".apk");
    }
}
